﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace Weazel.Badger.Vhdl.Types
{
	/// <summary>
	/// A litteral-based enumeration type is an enumeration 
	/// consisting of unique string names ...
	/// </summary>
  public class LitteralBasedEnumerationType : Type, IDeclarativeItem
  {
		/// <summary>
		/// Members of this enumerations
		/// </summary>
    private List<string> members = new List<string>();

    public LitteralBasedEnumerationType(int id, string name) 
			: base(new TypeId(20 + id, name), Vhdl.Types.ArrayType.UNDEFINED_WIDTH) 
    {
    }

		/// <summary>
		/// Add a member to this enumeration
		/// </summary>
		/// <param name="name">Member to add</param>
    public void AddTypeMember(string name)
    {
      if (!members.Contains(name))
        members.Add(name);
    }

		/// <summary>
		/// Check if this enumeration contains a 
		/// specific member
		/// </summary>
		/// <param name="name">Name of member to test</param>
		/// <returns>true if the argument string is a member of this enumeration</returns>
    public bool ContainsMember(string name)
    {
      return members.Contains(name);
    }

		/// <summary>
		/// Export to VHDL 
		/// </summary>
		/// <param name="writer"></param>
    public void Write(System.CodeDom.Compiler.IndentedTextWriter writer)
    {
      writer.WriteLine(string.Format("type {0} is (", this.TypeId.name));
      writer.Indent++;

      // for all but the last one ..
      for (int i = 0; i < members.Count - 1; i++)
        writer.WriteLine(members[i].ToString() + ",");

      writer.WriteLine(members[members.Count - 1].ToString());

      writer.Indent--;
      writer.WriteLine(");");
    }
  }
}
